#include <cstdlib>
#include <iostream>
#include <time.h>
#include <vector>

using namespace std;

class doubleList{
      private:
              vector<double> *dList;
      public:
	         doubleList();
	         ~doubleList();
	         void add_after(int ,int );
	         int insert_rand(double numb );
};

doubleList::doubleList(){
	this->dList = new vector<double>();
}

doubleList::~doubleList(){
	delete this->dList;
}


void doubleList::add_after(int i, double numb){
     
     if(i<0) cerr<<"Negative position number : "<< i <<endl;
     
     else if (i>= dList->size()) cerr<<"Position number bigger than the size of the list : "<< i <<endl;
     
     else {
             for ( int j = i+1 ; j < dList->size() ; j++ ) {
               dList->at(j)= dList->at(j) + numb;
               }
     }
}

int doubleList::insert_rand(double numb){
     
     int random;
     
     vector<double>::iterator it,it2;
    
     srand ( time(NULL) );
     random = rand() % (dList->size()-1) + 0;
     
      it = dList->begin();
      
      vector<double> anothervector (1,numb);

      dList->insert (it+random,anothervector.begin(),anothervector.end());

      return random;
          
}



int main(){
     
     doubleList c2 ;
     
     int rand1, rand2,rand3;
     
      rand1 = c2.insert_rand(2.3);
      cout<<"1st execution of insert_rand(2.3) and random position is : " << rand1 <<endl;
      
      rand2 = c2.insert_rand(7.8);
      cout<<"2nd execution of insert_rand(7.8) and random position is : " << rand2 <<endl;
      
      rand3 = c2.insert_rand(20);
      cout<<"3rd execution of insert_rand(10) and random position is : " << rand3 <<endl;
      
      c2.add_after(2,3);
      cout<<"1st execution of add_after(2,3)" << endl;     
     
      c2.add_after(2,3);
      cout<<"2nd execution of add_after(-2,3) with negative position number -2 : " << endl;     
     
      c2.add_after(103,3);
      cout<<"3rd execution of  add_after(103,3) with position number 103 : " << endl; 
          
     return 0;  
     
     
     }
     
     
     
